/*
 * UserControlPanel.fx
 * Author: Yu Min-ting
 * Created on 2009-7-13, 10:20:20
 */

package com.sjtu.fx.user;

import javafx.scene.*;
import javafx.stage.Stage;
import javafx.scene.control.*;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.scene.effect.*;
import javafx.scene.input.MouseEvent;

import javafx.scene.effect.*;

import javafx.scene.layout.*;
import com.sjtu.fx.tools.Panel;


public class UserControlPanel extends CustomNode {
    var panel:Panel;
    public var helloName:String ;
//    public var userLogout:Boolean = false;
    var welcomeText = Text {
        id: "welcomeText"
        font: Font {size:12 name: "Verdana Bold"}
        fill: Color.rgb(11,51,60)
        content: bind helloName
    };

    var logOut : Button = Button {
        text: "Log Out"
        font: Font {size:11 name: "Verdana Bold"}
        action: function () {
            this.visible = false;
            this.parent.lookup("loginPanel").visible = true;
            this.parent.lookup("topBooks").visible = true;
            this.parent.lookup("recommendBooks").visible = true;
            this.parent.lookup("updateBook").visible = false;
            this.parent.lookup("changePaswd").visible = false;
          //  userLogout = true;
        }
    }

    var watingList : Text = Text{
        content: "My wating list"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         onMouseEntered: function( e: MouseEvent ):Void {
                 watingList.fill =  Color.BLUE;
                 watingList.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                watingList.fill = Color.rgb(11,51,60);
                watingList.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {

        }
    }

    var checkBooks : Text = Text{
         content: "Check in / Check out"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}

         onMouseEntered: function( e: MouseEvent ):Void {
                checkBooks.fill =  Color.BLUE;
                checkBooks.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                checkBooks.fill = Color.rgb(11,51,60);
                checkBooks.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("userBookPage").visible = true;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("userBookPurchase").visible = false;
                this.parent.lookup("changePassWd").visible = false;
        }
    }
    var purchaseBooks : Text = Text{
         content: "Purchase Books"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         x: 145 y: 185

         onMouseEntered: function( e: MouseEvent ):Void {
                 purchaseBooks.fill =  Color.BLUE;
                 purchaseBooks.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                 purchaseBooks.fill = Color.rgb(11,51,60);
                 purchaseBooks.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("userBookPage").visible = false;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("userBookPurchase").visible = true;
                this.parent.lookup("changePassWd").visible = false;
        }
    }

    var changePw : Text = Text{
         content: "Change Password"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         x: 145 y: 185

         onMouseEntered: function( e: MouseEvent ):Void {
                changePw.fill =  Color.BLUE;
                changePw.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                changePw.fill = Color.rgb(11,51,60);
                changePw.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("userBookPage").visible = false;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("userBookPurchase").visible = false;
                this.parent.lookup("changePassWd").visible = true;
        }
    }

    override protected function create() : Node {
        Group{
            content:[
                 panel = Panel {
                    width:    290
                    height:   240
                    title:    "My Library"
                    translateX: 0
                    translateY: 0
                },
                HBox{
                    spacing: 20
                    translateX:80 translateY:50
                    content:[welcomeText,logOut]
                }

                 VBox{
                    spacing: 20
                    translateX:40 translateY: 80
                    content:[watingList, checkBooks, purchaseBooks, changePw]
                },

            ]
        }
     }

function run() {
    Stage {
       width: 350 height: 300
        scene: Scene {
            content: [
                Login {translateX: 40 translateY: 40}
            ]
        }
    }
}



}
